feat: notify on time changes in MockTimeSystem#964
Merged
Conversation
67690db to
b51f3cd
Compare
There was a problem hiding this comment.
Pull request overview
Adds an explicit StartTime concept to the MockTimeSystem time provider so callers can reliably retrieve the initial simulated time even after advancing the clock.
Changes:
- Introduce
StartTimeonITimeProvider. - Persist the initial time in
TimeProviderMockvia a read-onlyStartTimeproperty. - Add a unit test asserting
StartTimeremains the initial value after time advances.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| Tests/Testably.Abstractions.Testing.Tests/MockTimeSystemTests.cs | Adds coverage for TimeProvider.StartTime being set to the initial time and remaining stable. |
| Source/Testably.Abstractions.Testing/TimeSystem/TimeProviderMock.cs | Implements StartTime and initializes it from the initial _now. |
| Source/Testably.Abstractions.Testing/TimeSystem/ITimeProvider.cs | Extends the public time provider contract with StartTime and XML documentation. |
Source/Testably.Abstractions.Testing/TimeSystem/ITimeProvider.cs
Outdated
Show resolved
Hide resolved
StartTime to the time provider of the MockTimeSystemMockTimeSystem
4b01dce to
e200b02
Compare
|
|
This is addressed in release v6.0.0. |
This was referenced Mar 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



This pull request introduces significant improvements to the time system mocking infrastructure, focusing on extensibility and notification capabilities. The main changes include introducing an
ITimeProviderFactoryfor more flexible creation of time providers, enhancing notification support for time changes, and updating related APIs and documentation accordingly.Time provider extensibility and notification improvements:
ITimeProviderFactoryinterface and updatedTimeProvider.Now(),TimeProvider.Random(), andTimeProvider.Use()to return factories instead of direct time providers, allowing for more flexible and testable time provider creation.MockTimeSystemclass to accept anITimeProviderFactoryand to use a callback for time change notifications. The previous constructor acceptingITimeProviderwill be marked as obsolete.Time change notification enhancements:
TimeChangedcallback to theINotificationHandlerinterface and implemented it inNotificationHandler, allowing clients to be notified whenever the mocked time changes.TimeProviderMockto support the new time change notification mechanism and expose theStartTimeproperty, reflecting the initial time at which the provider was created.PeriodicTimerinITimeSystem#960